/*     */ package com.zimbra.qa.unittest;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.soap.AccountConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.SoapHttpTransport;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.HashMap;
/*     */ import java.util.Map;
/*     */ import junit.framework.TestCase;
/*     */ import org.junit.After;
/*     */ import org.junit.Before;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestCommunityIntegration
/*     */   extends TestCase
/*     */ {
/*  38 */   private Provisioning mProv = Provisioning.getInstance();
/*  39 */   private String DOMAIN_NAME = "testcommunity.domain.com";
/*  40 */   private String USER_NAME = "user1";
/*  41 */   private String COMMUNITY_BASE_URL = "http://zimbra.community.testcommunity.domain.com";
/*  42 */   private String COMMUNITY_HOME_URL = "/integration/zimbracollaboration";
/*  43 */   private String COMMUNITY_CLIENT_ID = "abcd";
/*  44 */   private String COMMUNITY_CLIENT_SECRET = "secret";
/*  45 */   Domain domain = null;
/*  46 */   Account testUser = null;
/*     */   
/*     */   @Before
/*     */   public void setUp() throws Exception
/*     */   {
/*  51 */     cleanup();
/*     */     
/*  53 */     Map<String, Object> attrs = new HashMap();
/*  54 */     attrs.put("zimbraCommunityAPIClientID", this.COMMUNITY_CLIENT_ID);
/*  55 */     attrs.put("zimbraCommunityAPIClientSecret", this.COMMUNITY_CLIENT_SECRET);
/*  56 */     attrs.put("zimbraCommunityUsernameMapping", "uid");
/*  57 */     attrs.put("zimbraCommunityBaseURL", this.COMMUNITY_BASE_URL);
/*  58 */     attrs.put("zimbraCommunityHomeURL", this.COMMUNITY_HOME_URL);
/*  59 */     this.domain = this.mProv.createDomain(this.DOMAIN_NAME, attrs);
/*  60 */     assertNotNull(this.domain);
/*  61 */     attrs = new HashMap();
/*  62 */     attrs.put("zimbraFeatureSocialExternalEnabled", "TRUE");
/*  63 */     this.testUser = this.mProv.createAccount(this.USER_NAME.concat("@").concat(this.DOMAIN_NAME), "test123", attrs);
/*     */   }
/*     */   
/*     */   @After
/*     */   public void tearDown()
/*     */     throws Exception
/*     */   {
/*  70 */     cleanup();
/*     */   }
/*     */   
/*     */   private void cleanup() throws Exception {
/*  74 */     Account a = this.mProv.getAccountByName(this.USER_NAME.concat("@").concat(this.DOMAIN_NAME));
/*  75 */     if (a != null) {
/*  76 */       this.mProv.deleteAccount(a.getId());
/*     */     }
/*  78 */     Domain d = this.mProv.getDomainByName(this.DOMAIN_NAME);
/*  79 */     if (d != null) {
/*  80 */       this.mProv.deleteDomain(d.getId());
/*     */     }
/*     */   }
/*     */   
/*     */   public void testGetInfo() throws Exception
/*     */   {
/*  86 */     SoapHttpTransport transport = new SoapHttpTransport(TestUtil.getSoapUrl());
/*  87 */     Element request = Element.create(transport.getRequestProtocol(), AccountConstants.AUTH_REQUEST);
/*  88 */     request.addElement("account").addAttribute("by", Key.AccountBy.name.name()).setText(this.testUser.getName());
/*  89 */     request.addElement("password").setText("test123");
/*     */     
/*  91 */     Element response = transport.invoke(request);
/*  92 */     String authToken = response.getElement("authToken").getText();
/*  93 */     transport.setAuthToken(authToken);
/*     */     
/*  95 */     request = Element.create(transport.getRequestProtocol(), AccountConstants.GET_INFO_REQUEST);
/*  96 */     response = transport.invoke(request);
/*  97 */     String communityURL = response.getAttribute("communityURL");
/*  98 */     assertNotNull(communityURL);
/*  99 */     assertTrue("community URL begin with " + this.COMMUNITY_BASE_URL, communityURL.startsWith(this.COMMUNITY_BASE_URL));
/* 100 */     assertTrue("community URL should contain username=" + this.testUser.getUid(), communityURL.contains(String.format("username=%s", new Object[] { this.testUser.getUid() })));
/* 101 */     assertTrue("community URL should contain redirect_uri=" + this.COMMUNITY_HOME_URL + " actual: " + communityURL, communityURL.contains(String.format("redirect_uri=%s", new Object[] { URLEncoder.encode(this.COMMUNITY_BASE_URL.concat(this.COMMUNITY_HOME_URL), "UTF8") })));
/* 102 */     assertTrue("community URL should contain configured client_id=" + this.COMMUNITY_CLIENT_ID, communityURL.contains(String.format("client_id=%s&", new Object[] { this.COMMUNITY_CLIENT_ID })));
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/TestCommunityIntegration.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */